<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>basictextformatter_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_basictextformatter_test.js.html">basictextformatter_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.editor.plugins.BasicTextFormatterTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.editor.plugins.BasicTextFormatterTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.Range&#39;);
<a name="line20"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line21"></a>goog.require(&#39;goog.editor.BrowserFeature&#39;);
<a name="line22"></a>goog.require(&#39;goog.editor.Command&#39;);
<a name="line23"></a>goog.require(&#39;goog.editor.Field&#39;);
<a name="line24"></a>goog.require(&#39;goog.editor.Plugin&#39;);
<a name="line25"></a>goog.require(&#39;goog.editor.plugins.BasicTextFormatter&#39;);
<a name="line26"></a>goog.require(&#39;goog.object&#39;);
<a name="line27"></a>goog.require(&#39;goog.style&#39;);
<a name="line28"></a>goog.require(&#39;goog.testing.ExpectedFailures&#39;);
<a name="line29"></a>goog.require(&#39;goog.testing.LooseMock&#39;);
<a name="line30"></a>goog.require(&#39;goog.testing.PropertyReplacer&#39;);
<a name="line31"></a>goog.require(&#39;goog.testing.editor.FieldMock&#39;);
<a name="line32"></a>goog.require(&#39;goog.testing.editor.TestHelper&#39;);
<a name="line33"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line34"></a>goog.require(&#39;goog.testing.mockmatchers&#39;);
<a name="line35"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line36"></a>
<a name="line37"></a>var stubs;
<a name="line38"></a>
<a name="line39"></a>var SAVED_HTML;
<a name="line40"></a>var FIELDMOCK;
<a name="line41"></a>var FORMATTER;
<a name="line42"></a>var ROOT;
<a name="line43"></a>var HELPER;
<a name="line44"></a>var OPEN_SUB;
<a name="line45"></a>var CLOSE_SUB;
<a name="line46"></a>var OPEN_SUPER;
<a name="line47"></a>var CLOSE_SUPER;
<a name="line48"></a>var MOCK_BLOCKQUOTE_STYLE = &#39;border-left: 1px solid gray;&#39;;
<a name="line49"></a>var MOCK_GET_BLOCKQUOTE_STYLES = function() {
<a name="line50"></a>  return MOCK_BLOCKQUOTE_STYLE;
<a name="line51"></a>};
<a name="line52"></a>
<a name="line53"></a>var REAL_FIELD;
<a name="line54"></a>var REAL_PLUGIN;
<a name="line55"></a>
<a name="line56"></a>var expectedFailures;
<a name="line57"></a>
<a name="line58"></a>function setUpPage() {
<a name="line59"></a>  stubs = new goog.testing.PropertyReplacer();
<a name="line60"></a>  SAVED_HTML = goog.dom.getElement(&#39;html&#39;).innerHTML;
<a name="line61"></a>  FIELDMOCK;
<a name="line62"></a>  FORMATTER;
<a name="line63"></a>  ROOT = goog.dom.getElement(&#39;root&#39;);
<a name="line64"></a>  HELPER;
<a name="line65"></a>  OPEN_SUB =
<a name="line66"></a>      goog.userAgent.WEBKIT &amp;&amp; !goog.userAgent.isVersionOrHigher(&#39;530&#39;) ?
<a name="line67"></a>      &#39;&lt;span class=&quot;Apple-style-span&quot; style=&quot;vertical-align: sub;&quot;&gt;&#39; :
<a name="line68"></a>      &#39;&lt;sub&gt;&#39;;
<a name="line69"></a>  CLOSE_SUB =
<a name="line70"></a>      goog.userAgent.WEBKIT &amp;&amp; !goog.userAgent.isVersionOrHigher(&#39;530&#39;) ?
<a name="line71"></a>      &#39;&lt;/span&gt;&#39; : &#39;&lt;/sub&gt;&#39;;
<a name="line72"></a>  OPEN_SUPER =
<a name="line73"></a>      goog.userAgent.WEBKIT &amp;&amp; !goog.userAgent.isVersionOrHigher(&#39;530&#39;) ?
<a name="line74"></a>      &#39;&lt;span class=&quot;Apple-style-span&quot; style=&quot;vertical-align: super;&quot;&gt;&#39; :
<a name="line75"></a>      &#39;&lt;sup&gt;&#39;;
<a name="line76"></a>  CLOSE_SUPER =
<a name="line77"></a>      goog.userAgent.WEBKIT &amp;&amp; !goog.userAgent.isVersionOrHigher(&#39;530&#39;) ?
<a name="line78"></a>      &#39;&lt;/span&gt;&#39; : &#39;&lt;/sup&gt;&#39;;
<a name="line79"></a>  expectedFailures = new goog.testing.ExpectedFailures();
<a name="line80"></a>}
<a name="line81"></a>
<a name="line82"></a>function setUp() {
<a name="line83"></a>  FIELDMOCK = new goog.testing.editor.FieldMock();
<a name="line84"></a>
<a name="line85"></a>  FORMATTER = new goog.editor.plugins.BasicTextFormatter();
<a name="line86"></a>  FORMATTER.fieldObject = FIELDMOCK;
<a name="line87"></a>}
<a name="line88"></a>
<a name="line89"></a>function setUpRealField() {
<a name="line90"></a>  REAL_FIELD = new goog.editor.Field(&#39;real-field&#39;);
<a name="line91"></a>  REAL_PLUGIN = new goog.editor.plugins.BasicTextFormatter();
<a name="line92"></a>  REAL_FIELD.registerPlugin(REAL_PLUGIN);
<a name="line93"></a>  REAL_FIELD.makeEditable();
<a name="line94"></a>}
<a name="line95"></a>
<a name="line96"></a>function setUpRealFieldIframe() {
<a name="line97"></a>  REAL_FIELD = new goog.editor.Field(&#39;iframe&#39;);
<a name="line98"></a>  FORMATTER = new goog.editor.plugins.BasicTextFormatter();
<a name="line99"></a>  REAL_FIELD.registerPlugin(FORMATTER);
<a name="line100"></a>  REAL_FIELD.makeEditable();
<a name="line101"></a>}
<a name="line102"></a>
<a name="line103"></a>function selectRealField() {
<a name="line104"></a>  goog.dom.Range.createFromNodeContents(REAL_FIELD.getElement()).select();
<a name="line105"></a>  REAL_FIELD.dispatchSelectionChangeEvent();
<a name="line106"></a>}
<a name="line107"></a>
<a name="line108"></a>function tearDown() {
<a name="line109"></a>  tearDownFontSizeTests();
<a name="line110"></a>
<a name="line111"></a>  if (REAL_FIELD) {
<a name="line112"></a>    REAL_FIELD.makeUneditable();
<a name="line113"></a>    REAL_FIELD.dispose();
<a name="line114"></a>    REAL_FIELD = null;
<a name="line115"></a>  }
<a name="line116"></a>
<a name="line117"></a>  expectedFailures.handleTearDown();
<a name="line118"></a>  stubs.reset();
<a name="line119"></a>
<a name="line120"></a>  goog.dom.getElement(&#39;html&#39;).innerHTML = SAVED_HTML;
<a name="line121"></a>}
<a name="line122"></a>
<a name="line123"></a>function setUpListAndBlockquoteTests() {
<a name="line124"></a>  var htmlDiv = document.getElementById(&#39;html&#39;);
<a name="line125"></a>  HELPER = new goog.testing.editor.TestHelper(htmlDiv);
<a name="line126"></a>  HELPER.setUpEditableElement();
<a name="line127"></a>
<a name="line128"></a>  FIELDMOCK.getElement();
<a name="line129"></a>  FIELDMOCK.$anyTimes();
<a name="line130"></a>  FIELDMOCK.$returns(htmlDiv);
<a name="line131"></a>}
<a name="line132"></a>
<a name="line133"></a>function tearDownHelper() {
<a name="line134"></a>  HELPER.tearDownEditableElement();
<a name="line135"></a>  HELPER.dispose();
<a name="line136"></a>  HELPER = null;
<a name="line137"></a>}
<a name="line138"></a>
<a name="line139"></a>function tearDownListAndBlockquoteTests() {
<a name="line140"></a>  tearDownHelper();
<a name="line141"></a>}
<a name="line142"></a>
<a name="line143"></a>function testIEList() {
<a name="line144"></a>  if (goog.userAgent.IE) {
<a name="line145"></a>    setUpListAndBlockquoteTests();
<a name="line146"></a>
<a name="line147"></a>    FIELDMOCK.queryCommandValue(&#39;rtl&#39;).$returns(null);
<a name="line148"></a>
<a name="line149"></a>    FIELDMOCK.$replay();
<a name="line150"></a>    var ul = goog.dom.getElement(&#39;outerUL&#39;);
<a name="line151"></a>    goog.dom.Range.createFromNodeContents(ul.firstChild.firstChild).select();
<a name="line152"></a>    FORMATTER.fixIELists_();
<a name="line153"></a>    assertFalse(&#39;Unordered list must not have ordered type&#39;, ul.type == &#39;1&#39;);
<a name="line154"></a>    var ol = goog.dom.getElement(&#39;ol&#39;);
<a name="line155"></a>    ol.type = &#39;disc&#39;;
<a name="line156"></a>    goog.dom.Range.createFromNodeContents(ol.firstChild.firstChild).select();
<a name="line157"></a>    FORMATTER.fixIELists_();
<a name="line158"></a>    assertFalse(&#39;Ordered list must not have unordered type&#39;,
<a name="line159"></a>        ol.type == &#39;disc&#39;);
<a name="line160"></a>    ol.type = &#39;1&#39;;
<a name="line161"></a>    goog.dom.Range.createFromNodeContents(ol.firstChild.firstChild).select();
<a name="line162"></a>    FORMATTER.fixIELists_();
<a name="line163"></a>    assertTrue(&#39;Ordered list must retain ordered list type&#39;,
<a name="line164"></a>        ol.type == &#39;1&#39;);
<a name="line165"></a>    tearDownListAndBlockquoteTests();
<a name="line166"></a>  }
<a name="line167"></a>}
<a name="line168"></a>
<a name="line169"></a>function testWebKitList() {
<a name="line170"></a>  if (goog.userAgent.WEBKIT) {
<a name="line171"></a>    setUpListAndBlockquoteTests();
<a name="line172"></a>
<a name="line173"></a>    FIELDMOCK.queryCommandValue(&#39;rtl&#39;).$returns(null);
<a name="line174"></a>
<a name="line175"></a>    FIELDMOCK.$replay();
<a name="line176"></a>    var ul = document.getElementById(&#39;outerUL&#39;);
<a name="line177"></a>    var html = ul.innerHTML;
<a name="line178"></a>    goog.dom.Range.createFromNodeContents(ul).select();
<a name="line179"></a>
<a name="line180"></a>    FORMATTER.fixSafariLists_();
<a name="line181"></a>    assertEquals(&#39;Contents of UL shouldn\&#39;t change&#39;,
<a name="line182"></a>        html, ul.innerHTML);
<a name="line183"></a>
<a name="line184"></a>    ul = document.getElementById(&#39;outerUL2&#39;);
<a name="line185"></a>    goog.dom.Range.createFromNodeContents(ul).select();
<a name="line186"></a>
<a name="line187"></a>    FORMATTER.fixSafariLists_();
<a name="line188"></a>    var childULs = ul.getElementsByTagName(&#39;ul&#39;);
<a name="line189"></a>    assertEquals(&#39;UL should have one child UL&#39;,
<a name="line190"></a>        1, childULs.length);
<a name="line191"></a>    tearDownListAndBlockquoteTests();
<a name="line192"></a>  }
<a name="line193"></a>}
<a name="line194"></a>
<a name="line195"></a>function testGeckoListFont() {
<a name="line196"></a>  if (goog.userAgent.GECKO) {
<a name="line197"></a>    setUpListAndBlockquoteTests();
<a name="line198"></a>    FIELDMOCK.queryCommandValue(
<a name="line199"></a>        goog.editor.Command.DEFAULT_TAG).$returns(&#39;BR&#39;).$times(2);
<a name="line200"></a>
<a name="line201"></a>    FIELDMOCK.$replay();
<a name="line202"></a>    var p = goog.dom.getElement(&#39;geckolist&#39;);
<a name="line203"></a>    var font = p.firstChild;
<a name="line204"></a>    goog.dom.Range.createFromNodeContents(font).select();
<a name="line205"></a>    retVal = FORMATTER.beforeInsertListGecko_();
<a name="line206"></a>    assertFalse(&#39;Workaround shouldn\&#39;t be applied when not needed&#39;, retVal);
<a name="line207"></a>
<a name="line208"></a>    font.innerHTML = &#39;&#39;;
<a name="line209"></a>    goog.dom.Range.createFromNodeContents(font).select();
<a name="line210"></a>    var retVal = FORMATTER.beforeInsertListGecko_();
<a name="line211"></a>    assertTrue(&#39;Workaround should be applied when needed&#39;, retVal);
<a name="line212"></a>    document.execCommand(&#39;insertorderedlist&#39;, false, true);
<a name="line213"></a>    assertTrue(&#39;Font should be Courier&#39;,
<a name="line214"></a>        /courier/i.test(document.queryCommandValue(&#39;fontname&#39;)));
<a name="line215"></a>    tearDownListAndBlockquoteTests();
<a name="line216"></a>  }
<a name="line217"></a>}
<a name="line218"></a>
<a name="line219"></a>function testSwitchListType() {
<a name="line220"></a>  if (!goog.userAgent.WEBKIT) {
<a name="line221"></a>    return;
<a name="line222"></a>  }
<a name="line223"></a>  // Test that we&#39;re not seeing https://bugs.webkit.org/show_bug.cgi?id=19539,
<a name="line224"></a>  // the type of multi-item lists.
<a name="line225"></a>  setUpListAndBlockquoteTests();
<a name="line226"></a>
<a name="line227"></a>  FIELDMOCK.$replay();
<a name="line228"></a>  var list = goog.dom.getElement(&#39;switchListType&#39;);
<a name="line229"></a>  var parent = goog.dom.getParentElement(list);
<a name="line230"></a>
<a name="line231"></a>  goog.dom.Range.createFromNodeContents(list).select();
<a name="line232"></a>  FORMATTER.execCommandInternal(&#39;insertunorderedlist&#39;);
<a name="line233"></a>  list = goog.dom.getFirstElementChild(parent);
<a name="line234"></a>  assertEquals(goog.dom.TagName.UL, list.tagName);
<a name="line235"></a>  assertEquals(3, goog.dom.getElementsByTagNameAndClass(
<a name="line236"></a>      goog.dom.TagName.LI, null, list).length);
<a name="line237"></a>
<a name="line238"></a>  goog.dom.Range.createFromNodeContents(list).select();
<a name="line239"></a>  FORMATTER.execCommandInternal(&#39;insertorderedlist&#39;);
<a name="line240"></a>  list = goog.dom.getFirstElementChild(parent);
<a name="line241"></a>  assertEquals(goog.dom.TagName.OL, list.tagName);
<a name="line242"></a>  assertEquals(3, goog.dom.getElementsByTagNameAndClass(
<a name="line243"></a>      goog.dom.TagName.LI, null, list).length);
<a name="line244"></a>
<a name="line245"></a>  tearDownListAndBlockquoteTests();
<a name="line246"></a>}
<a name="line247"></a>
<a name="line248"></a>function setUpSubSuperTests() {
<a name="line249"></a>  ROOT.innerHTML = &#39;12345&#39;;
<a name="line250"></a>  HELPER = new goog.testing.editor.TestHelper(ROOT);
<a name="line251"></a>  HELPER.setUpEditableElement();
<a name="line252"></a>}
<a name="line253"></a>
<a name="line254"></a>function tearDownSubSuperTests() {
<a name="line255"></a>  tearDownHelper();
<a name="line256"></a>}
<a name="line257"></a>
<a name="line258"></a>function testSubscriptRemovesSuperscript() {
<a name="line259"></a>  setUpSubSuperTests();
<a name="line260"></a>  FIELDMOCK.$replay();
<a name="line261"></a>
<a name="line262"></a>  HELPER.select(&#39;12345&#39;, 1, &#39;12345&#39;, 4); // Selects &#39;234&#39;.
<a name="line263"></a>  FORMATTER.execCommandInternal(
<a name="line264"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.SUPERSCRIPT);
<a name="line265"></a>  HELPER.assertHtmlMatches(&#39;1&#39; + OPEN_SUPER + &#39;234&#39; + CLOSE_SUPER + &#39;5&#39;);
<a name="line266"></a>  FORMATTER.execCommandInternal(
<a name="line267"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.SUBSCRIPT);
<a name="line268"></a>  HELPER.assertHtmlMatches(&#39;1&#39; + OPEN_SUB + &#39;234&#39; + CLOSE_SUB + &#39;5&#39;);
<a name="line269"></a>
<a name="line270"></a>  FIELDMOCK.$verify();
<a name="line271"></a>  tearDownSubSuperTests();
<a name="line272"></a>}
<a name="line273"></a>
<a name="line274"></a>function testSuperscriptRemovesSubscript() {
<a name="line275"></a>  setUpSubSuperTests();
<a name="line276"></a>  FIELDMOCK.$replay();
<a name="line277"></a>
<a name="line278"></a>  HELPER.select(&#39;12345&#39;, 1, &#39;12345&#39;, 4); // Selects &#39;234&#39;.
<a name="line279"></a>  FORMATTER.execCommandInternal(
<a name="line280"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.SUBSCRIPT);
<a name="line281"></a>  HELPER.assertHtmlMatches(&#39;1&#39; + OPEN_SUB + &#39;234&#39; + CLOSE_SUB + &#39;5&#39;);
<a name="line282"></a>  FORMATTER.execCommandInternal(
<a name="line283"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.SUPERSCRIPT);
<a name="line284"></a>  HELPER.assertHtmlMatches(&#39;1&#39; + OPEN_SUPER + &#39;234&#39; + CLOSE_SUPER + &#39;5&#39;);
<a name="line285"></a>
<a name="line286"></a>  FIELDMOCK.$verify();
<a name="line287"></a>  tearDownSubSuperTests();
<a name="line288"></a>}
<a name="line289"></a>
<a name="line290"></a>function testSubscriptRemovesSuperscriptIntersecting() {
<a name="line291"></a>  // Tests: 12345 , sup(23) , sub(34) ==&gt; 1+sup(2)+sub(34)+5
<a name="line292"></a>  // This is more complex because the sub and sup calls are made on separate
<a name="line293"></a>  // fields which intersect each other and queryCommandValue seems to return
<a name="line294"></a>  // false if the command is only applied to part of the field.
<a name="line295"></a>  setUpSubSuperTests();
<a name="line296"></a>  FIELDMOCK.$replay();
<a name="line297"></a>
<a name="line298"></a>  HELPER.select(&#39;12345&#39;, 1, &#39;12345&#39;, 3); // Selects &#39;23&#39;.
<a name="line299"></a>  FORMATTER.execCommandInternal(
<a name="line300"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.SUPERSCRIPT);
<a name="line301"></a>  HELPER.assertHtmlMatches(&#39;1&#39; + OPEN_SUPER + &#39;23&#39; + CLOSE_SUPER + &#39;45&#39;);
<a name="line302"></a>  HELPER.select(&#39;23&#39;, 1, &#39;45&#39;, 1); // Selects &#39;34&#39;.
<a name="line303"></a>  FORMATTER.execCommandInternal(
<a name="line304"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.SUBSCRIPT);
<a name="line305"></a>  HELPER.assertHtmlMatches(&#39;1&#39; + OPEN_SUPER + &#39;2&#39; + CLOSE_SUPER +
<a name="line306"></a>                           OPEN_SUB + &#39;34&#39; + CLOSE_SUB + &#39;5&#39;);
<a name="line307"></a>
<a name="line308"></a>  FIELDMOCK.$verify();
<a name="line309"></a>  tearDownSubSuperTests();
<a name="line310"></a>}
<a name="line311"></a>
<a name="line312"></a>function testSuperscriptRemovesSubscriptIntersecting() {
<a name="line313"></a>  // Tests: 12345 , sub(23) , sup(34) ==&gt; 1+sub(2)+sup(34)+5
<a name="line314"></a>  setUpSubSuperTests();
<a name="line315"></a>  FIELDMOCK.$replay();
<a name="line316"></a>
<a name="line317"></a>  HELPER.select(&#39;12345&#39;, 1, &#39;12345&#39;, 3); // Selects &#39;23&#39;.
<a name="line318"></a>  FORMATTER.execCommandInternal(
<a name="line319"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.SUBSCRIPT);
<a name="line320"></a>  HELPER.assertHtmlMatches(&#39;1&#39; + OPEN_SUB + &#39;23&#39; + CLOSE_SUB + &#39;45&#39;);
<a name="line321"></a>  HELPER.select(&#39;23&#39;, 1, &#39;45&#39;, 1); // Selects &#39;34&#39;.
<a name="line322"></a>  FORMATTER.execCommandInternal(
<a name="line323"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.SUPERSCRIPT);
<a name="line324"></a>  HELPER.assertHtmlMatches(&#39;1&#39; + OPEN_SUB + &#39;2&#39; + CLOSE_SUB +
<a name="line325"></a>                           OPEN_SUPER + &#39;34&#39; + CLOSE_SUPER + &#39;5&#39;);
<a name="line326"></a>
<a name="line327"></a>  FIELDMOCK.$verify();
<a name="line328"></a>  tearDownSubSuperTests();
<a name="line329"></a>}
<a name="line330"></a>
<a name="line331"></a>function setUpLinkTests(url, isEditable) {
<a name="line332"></a>  stubs.set(window, &#39;prompt&#39;, function() {
<a name="line333"></a>    return url;
<a name="line334"></a>  });
<a name="line335"></a>
<a name="line336"></a>  ROOT.innerHTML = &#39;12345&#39;;
<a name="line337"></a>  HELPER = new goog.testing.editor.TestHelper(ROOT);
<a name="line338"></a>  if (isEditable) {
<a name="line339"></a>    HELPER.setUpEditableElement();
<a name="line340"></a>    FIELDMOCK.execCommand(goog.editor.Command.MODAL_LINK_EDITOR,
<a name="line341"></a>        goog.testing.mockmatchers.isObject).$returns(undefined);
<a name="line342"></a>    FORMATTER.focusField_ = function() {
<a name="line343"></a>      throw &#39;Field should not be re-focused&#39;;
<a name="line344"></a>    };
<a name="line345"></a>  }
<a name="line346"></a>
<a name="line347"></a>  FIELDMOCK.getElement().$anyTimes().$returns(ROOT);
<a name="line348"></a>
<a name="line349"></a>  FIELDMOCK.setModalMode(true);
<a name="line350"></a>
<a name="line351"></a>  FIELDMOCK.isSelectionEditable().$anyTimes().$returns(isEditable);
<a name="line352"></a>}
<a name="line353"></a>
<a name="line354"></a>function tearDownLinkTests() {
<a name="line355"></a>  tearDownHelper();
<a name="line356"></a>}
<a name="line357"></a>
<a name="line358"></a>function testLink() {
<a name="line359"></a>  setUpLinkTests(&#39;http://www.x.com/&#39;, true);
<a name="line360"></a>  FIELDMOCK.$replay();
<a name="line361"></a>
<a name="line362"></a>  HELPER.select(&#39;12345&#39;, 3);
<a name="line363"></a>  FORMATTER.execCommandInternal(goog.editor.Command.LINK);
<a name="line364"></a>  HELPER.assertHtmlMatches(
<a name="line365"></a>      goog.editor.BrowserFeature.GETS_STUCK_IN_LINKS ?
<a name="line366"></a>          &#39;123&lt;a href=&quot;http://www.x.com/&quot;&gt;http://www.x.com/&lt;/a&gt;&amp;nbsp;45&#39; :
<a name="line367"></a>          &#39;123&lt;a href=&quot;http://www.x.com/&quot;&gt;http://www.x.com/&lt;/a&gt;45&#39;);
<a name="line368"></a>
<a name="line369"></a>  FIELDMOCK.$verify();
<a name="line370"></a>  tearDownLinkTests();
<a name="line371"></a>}
<a name="line372"></a>
<a name="line373"></a>function testSelectedLink() {
<a name="line374"></a>  setUpLinkTests(&#39;http://www.x.com/&#39;, true);
<a name="line375"></a>  FIELDMOCK.$replay();
<a name="line376"></a>
<a name="line377"></a>  HELPER.select(&#39;12345&#39;, 1, &#39;12345&#39;, 4);
<a name="line378"></a>  FORMATTER.execCommandInternal(goog.editor.Command.LINK);
<a name="line379"></a>  HELPER.assertHtmlMatches(
<a name="line380"></a>      goog.editor.BrowserFeature.GETS_STUCK_IN_LINKS ?
<a name="line381"></a>          &#39;1&lt;a href=&quot;http://www.x.com/&quot;&gt;234&lt;/a&gt;&amp;nbsp;5&#39; :
<a name="line382"></a>          &#39;1&lt;a href=&quot;http://www.x.com/&quot;&gt;234&lt;/a&gt;5&#39;);
<a name="line383"></a>
<a name="line384"></a>  FIELDMOCK.$verify();
<a name="line385"></a>  tearDownLinkTests();
<a name="line386"></a>}
<a name="line387"></a>
<a name="line388"></a>function testCanceledLink() {
<a name="line389"></a>  setUpLinkTests(undefined, true);
<a name="line390"></a>  FIELDMOCK.$replay();
<a name="line391"></a>
<a name="line392"></a>  HELPER.select(&#39;12345&#39;, 1, &#39;12345&#39;, 4);
<a name="line393"></a>  FORMATTER.execCommandInternal(goog.editor.Command.LINK);
<a name="line394"></a>  HELPER.assertHtmlMatches(&#39;12345&#39;);
<a name="line395"></a>
<a name="line396"></a>  assertEquals(&#39;234&#39;, FIELDMOCK.getRange().getText());
<a name="line397"></a>
<a name="line398"></a>  FIELDMOCK.$verify();
<a name="line399"></a>  tearDownLinkTests();
<a name="line400"></a>}
<a name="line401"></a>
<a name="line402"></a>function testUnfocusedLink() {
<a name="line403"></a>  FIELDMOCK.$reset();
<a name="line404"></a>  FIELDMOCK.getEditableDomHelper().
<a name="line405"></a>      $anyTimes().
<a name="line406"></a>      $returns(goog.dom.getDomHelper(window.document));
<a name="line407"></a>  setUpLinkTests(undefined, false);
<a name="line408"></a>  FIELDMOCK.getRange().$anyTimes().$returns(null);
<a name="line409"></a>  FIELDMOCK.$replay();
<a name="line410"></a>
<a name="line411"></a>  FORMATTER.execCommandInternal(goog.editor.Command.LINK);
<a name="line412"></a>  HELPER.assertHtmlMatches(&#39;12345&#39;);
<a name="line413"></a>
<a name="line414"></a>  FIELDMOCK.$verify();
<a name="line415"></a>  tearDownLinkTests();
<a name="line416"></a>}
<a name="line417"></a>
<a name="line418"></a>function setUpJustifyTests(html) {
<a name="line419"></a>  ROOT.innerHTML = html;
<a name="line420"></a>  HELPER = new goog.testing.editor.TestHelper(ROOT);
<a name="line421"></a>  HELPER.setUpEditableElement(ROOT);
<a name="line422"></a>
<a name="line423"></a>  FIELDMOCK.getElement();
<a name="line424"></a>  FIELDMOCK.$anyTimes();
<a name="line425"></a>  FIELDMOCK.$returns(ROOT);
<a name="line426"></a>
<a name="line427"></a>  FIELDMOCK.getElement();
<a name="line428"></a>  FIELDMOCK.$anyTimes();
<a name="line429"></a>  FIELDMOCK.$returns(ROOT);
<a name="line430"></a>}
<a name="line431"></a>
<a name="line432"></a>function tearDownJustifyTests() {
<a name="line433"></a>  tearDownHelper();
<a name="line434"></a>}
<a name="line435"></a>
<a name="line436"></a>function testJustify() {
<a name="line437"></a>  setUpJustifyTests(&#39;&lt;div&gt;abc&lt;/div&gt;&lt;p&gt;def&lt;/p&gt;&lt;div&gt;ghi&lt;/div&gt;&#39;);
<a name="line438"></a>  FIELDMOCK.$replay();
<a name="line439"></a>
<a name="line440"></a>  HELPER.select(&#39;abc&#39;, 1, &#39;def&#39;, 1); // Selects &#39;bcd&#39;.
<a name="line441"></a>  FORMATTER.execCommandInternal(
<a name="line442"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_CENTER);
<a name="line443"></a>  HELPER.assertHtmlMatches(
<a name="line444"></a>      &#39;&lt;div style=&quot;text-align: center&quot;&gt;abc&lt;/div&gt;&#39; +
<a name="line445"></a>      &#39;&lt;p style=&quot;text-align: center&quot;&gt;def&lt;/p&gt;&#39; +
<a name="line446"></a>      &#39;&lt;div&gt;ghi&lt;/div&gt;&#39;);
<a name="line447"></a>
<a name="line448"></a>  FIELDMOCK.$verify();
<a name="line449"></a>  tearDownJustifyTests();
<a name="line450"></a>}
<a name="line451"></a>
<a name="line452"></a>function testJustifyInInline() {
<a name="line453"></a>  setUpJustifyTests(&#39;&lt;div&gt;a&lt;i&gt;b&lt;/i&gt;c&lt;/div&gt;&lt;div&gt;d&lt;/div&gt;&#39;);
<a name="line454"></a>  FIELDMOCK.$replay();
<a name="line455"></a>
<a name="line456"></a>  HELPER.select(&#39;b&#39;, 0, &#39;b&#39;, 1); // Selects &#39;b&#39;.
<a name="line457"></a>  FORMATTER.execCommandInternal(
<a name="line458"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_CENTER);
<a name="line459"></a>  HELPER.assertHtmlMatches(
<a name="line460"></a>      &#39;&lt;div style=&quot;text-align: center&quot;&gt;a&lt;i&gt;b&lt;/i&gt;c&lt;/div&gt;&lt;div&gt;d&lt;/div&gt;&#39;);
<a name="line461"></a>
<a name="line462"></a>  FIELDMOCK.$verify();
<a name="line463"></a>  tearDownJustifyTests();
<a name="line464"></a>}
<a name="line465"></a>
<a name="line466"></a>function testJustifyInBlock() {
<a name="line467"></a>  setUpJustifyTests(&#39;&lt;div&gt;a&lt;div&gt;b&lt;/div&gt;c&lt;/div&gt;&#39;);
<a name="line468"></a>  FIELDMOCK.$replay();
<a name="line469"></a>
<a name="line470"></a>  HELPER.select(&#39;b&#39;, 0, &#39;b&#39;, 1); // Selects &#39;h&#39;.
<a name="line471"></a>  FORMATTER.execCommandInternal(
<a name="line472"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_CENTER);
<a name="line473"></a>  HELPER.assertHtmlMatches(
<a name="line474"></a>      &#39;&lt;div&gt;a&lt;div style=&quot;text-align: center&quot;&gt;b&lt;/div&gt;c&lt;/div&gt;&#39;);
<a name="line475"></a>
<a name="line476"></a>  FIELDMOCK.$verify();
<a name="line477"></a>  tearDownJustifyTests();
<a name="line478"></a>}
<a name="line479"></a>
<a name="line480"></a>var isFontSizeTest = false;
<a name="line481"></a>var defaultFontSizeMap;
<a name="line482"></a>
<a name="line483"></a>function setUpFontSizeTests() {
<a name="line484"></a>  isFontSizeTest = true;
<a name="line485"></a>  ROOT.innerHTML = &#39;1&lt;span style=&quot;font-size:2px&quot;&gt;23&lt;/span&gt;4&#39; +
<a name="line486"></a>                   &#39;&lt;span style=&quot;font-size:5px; white-space:pre&quot;&gt;56&lt;/span&gt;7&#39;;
<a name="line487"></a>  HELPER = new goog.testing.editor.TestHelper(ROOT);
<a name="line488"></a>  HELPER.setUpEditableElement();
<a name="line489"></a>  FIELDMOCK.getElement().$returns(ROOT).$anyTimes();
<a name="line490"></a>
<a name="line491"></a>  // Map representing the sizes of the text in the HTML snippet used in these
<a name="line492"></a>  // tests. The key is the exact text content of each text node, and the value
<a name="line493"></a>  // is the initial size of the font in pixels. Since tests may cause a text
<a name="line494"></a>  // node to be split in two, this also contains keys that initially don&#39;t
<a name="line495"></a>  // match any text node, but may match one later if an existing node is
<a name="line496"></a>  // split. The value for these keys is null, signifying no text node should
<a name="line497"></a>  // exist with that content.
<a name="line498"></a>  defaultFontSizeMap = {
<a name="line499"></a>    &#39;1&#39;: 16,
<a name="line500"></a>    &#39;2&#39;: null,
<a name="line501"></a>    &#39;23&#39;: 2,
<a name="line502"></a>    &#39;3&#39;: null,
<a name="line503"></a>    &#39;4&#39;: 16,
<a name="line504"></a>    &#39;5&#39;: null,
<a name="line505"></a>    &#39;56&#39;: 5,
<a name="line506"></a>    &#39;6&#39;: null,
<a name="line507"></a>    &#39;7&#39;: 16
<a name="line508"></a>  };
<a name="line509"></a>  assertFontSizes(&#39;Assertion failed on default font sizes!&#39;, {});
<a name="line510"></a>}
<a name="line511"></a>
<a name="line512"></a>function tearDownFontSizeTests() {
<a name="line513"></a>  if (isFontSizeTest) {
<a name="line514"></a>    tearDownHelper();
<a name="line515"></a>    isFontSizeTest = false;
<a name="line516"></a>  }
<a name="line517"></a>}
<a name="line518"></a>
<a name="line519"></a>
<a name="line520"></a>/**
<a name="line521"></a> * Asserts that the text nodes set up by setUpFontSizeTests() have had their
<a name="line522"></a> * font sizes changed as described by sizeChangesMap.
<a name="line523"></a> * @param {string} msg Assertion error message.
<a name="line524"></a> * @param {Object.&lt;string, number|null&gt;} sizeChangesMap Maps the text content
<a name="line525"></a> *     of a text node to be measured to its expected font size in pixels, or
<a name="line526"></a> *     null if that text node should not be present in the document (i.e.
<a name="line527"></a> *     because it was split into two). Only the text nodes that have changed
<a name="line528"></a> *     from their default need to be specified.
<a name="line529"></a> */
<a name="line530"></a>function assertFontSizes(msg, sizeChangesMap) {
<a name="line531"></a>  goog.object.extend(defaultFontSizeMap, sizeChangesMap);
<a name="line532"></a>  for (var k in defaultFontSizeMap) {
<a name="line533"></a>    var node = HELPER.findTextNode(k);
<a name="line534"></a>    var expected = defaultFontSizeMap[k];
<a name="line535"></a>    if (expected) {
<a name="line536"></a>      assertNotNull(msg + &#39; [couldn\&#39;t find text node &quot;&#39; + k + &#39;&quot;]&#39;, node);
<a name="line537"></a>      assertEquals(msg + &#39; [incorrect font size for &quot;&#39; + k + &#39;&quot;]&#39;,
<a name="line538"></a>                   expected, goog.style.getFontSize(node.parentNode));
<a name="line539"></a>    } else {
<a name="line540"></a>      assertNull(msg + &#39; [unexpected text node &quot;&#39; + k + &#39;&quot;]&#39;, node);
<a name="line541"></a>    }
<a name="line542"></a>  }
<a name="line543"></a>}
<a name="line544"></a>
<a name="line545"></a>
<a name="line546"></a>/**
<a name="line547"></a> * Regression test for {@bug 1286408}. Tests that when you change the font
<a name="line548"></a> * size of a selection, any font size styles that were nested inside are
<a name="line549"></a> * removed.
<a name="line550"></a> */
<a name="line551"></a>function testFontSizeOverridesStyleAttr() {
<a name="line552"></a>  setUpFontSizeTests();
<a name="line553"></a>  FIELDMOCK.$replay();
<a name="line554"></a>
<a name="line555"></a>  HELPER.select(&#39;1&#39;, 0, &#39;4&#39;, 1); // Selects 1234.
<a name="line556"></a>  FORMATTER.execCommandInternal(
<a name="line557"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.FONT_SIZE, 6);
<a name="line558"></a>
<a name="line559"></a>  assertFontSizes(&#39;New font size should override existing font size&#39;,
<a name="line560"></a>                  {&#39;1&#39;: 32, &#39;23&#39;: 32, &#39;4&#39;: 32});
<a name="line561"></a>
<a name="line562"></a>  if (goog.editor.BrowserFeature.DOESNT_OVERRIDE_FONT_SIZE_IN_STYLE_ATTR) {
<a name="line563"></a>    var span = HELPER.findTextNode(&#39;23&#39;).parentNode;
<a name="line564"></a>    assertFalse(&#39;Style attribute should be gone&#39;,
<a name="line565"></a>        span.getAttributeNode(&#39;style&#39;) != null &amp;&amp;
<a name="line566"></a>        span.getAttributeNode(&#39;style&#39;).specified);
<a name="line567"></a>  }
<a name="line568"></a>
<a name="line569"></a>  FIELDMOCK.$verify();
<a name="line570"></a>}
<a name="line571"></a>
<a name="line572"></a>
<a name="line573"></a>/**
<a name="line574"></a> * Make sure the style stripping works when the selection starts and stops in
<a name="line575"></a> * different nodes that both contain font size styles.
<a name="line576"></a> */
<a name="line577"></a>function testFontSizeOverridesStyleAttrMultiNode() {
<a name="line578"></a>  setUpFontSizeTests();
<a name="line579"></a>  FIELDMOCK.$replay();
<a name="line580"></a>
<a name="line581"></a>  HELPER.select(&#39;23&#39;, 0, &#39;56&#39;, 2); // Selects 23456.
<a name="line582"></a>  FORMATTER.execCommandInternal(
<a name="line583"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.FONT_SIZE, 6);
<a name="line584"></a>  var span = HELPER.findTextNode(&#39;23&#39;).parentNode;
<a name="line585"></a>  var span2 = HELPER.findTextNode(&#39;56&#39;).parentNode;
<a name="line586"></a>
<a name="line587"></a>  assertFontSizes(
<a name="line588"></a>      &#39;New font size should override existing font size in all spans&#39;,
<a name="line589"></a>      {&#39;23&#39;: 32, &#39;4&#39;: 32, &#39;56&#39;: 32});
<a name="line590"></a>  var whiteSpace = goog.userAgent.IE ?
<a name="line591"></a>                   goog.style.getCascadedStyle(span2, &#39;whiteSpace&#39;) :
<a name="line592"></a>                   goog.style.getComputedStyle(span2, &#39;whiteSpace&#39;);
<a name="line593"></a>  assertEquals(&#39;Whitespace style in last span should have been left&#39;,
<a name="line594"></a>               &#39;pre&#39;, whiteSpace);
<a name="line595"></a>
<a name="line596"></a>  if (goog.editor.BrowserFeature.DOESNT_OVERRIDE_FONT_SIZE_IN_STYLE_ATTR) {
<a name="line597"></a>    assertFalse(&#39;Style attribute should be gone from first span&#39;,
<a name="line598"></a>        span.getAttributeNode(&#39;style&#39;) != null &amp;&amp;
<a name="line599"></a>        span.getAttributeNode(&#39;style&#39;).specified);
<a name="line600"></a>    assertTrue(&#39;Style attribute should not be gone from last span&#39;,
<a name="line601"></a>        span2.getAttributeNode(&#39;style&#39;) != null &amp;&amp;
<a name="line602"></a>        span2.getAttributeNode(&#39;style&#39;).specified);
<a name="line603"></a>  }
<a name="line604"></a>
<a name="line605"></a>  FIELDMOCK.$verify();
<a name="line606"></a>}
<a name="line607"></a>
<a name="line608"></a>
<a name="line609"></a>/**
<a name="line610"></a> * Makes sure the font size style is not removed when only a part of the
<a name="line611"></a> * element with font size style is selected during the font size command.
<a name="line612"></a> */
<a name="line613"></a>function testFontSizeDoesntOverrideStyleAttr() {
<a name="line614"></a>  setUpFontSizeTests();
<a name="line615"></a>  FIELDMOCK.$replay();
<a name="line616"></a>
<a name="line617"></a>  HELPER.select(&#39;23&#39;, 1, &#39;4&#39;, 1); // Selects 34 (half of span with font size).
<a name="line618"></a>  FORMATTER.execCommandInternal(
<a name="line619"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.FONT_SIZE, 6);
<a name="line620"></a>
<a name="line621"></a>  assertFontSizes(
<a name="line622"></a>      &#39;New font size shouldn\&#39;t override existing font size before selection&#39;,
<a name="line623"></a>      {&#39;2&#39;: 2, &#39;23&#39;: null, &#39;3&#39;: 32, &#39;4&#39;: 32});
<a name="line624"></a>
<a name="line625"></a>  FIELDMOCK.$verify();
<a name="line626"></a>}
<a name="line627"></a>
<a name="line628"></a>
<a name="line629"></a>/**
<a name="line630"></a> * Makes sure the font size style is not removed when only a part of the
<a name="line631"></a> * element with font size style is selected during the font size command, but
<a name="line632"></a> * is removed for another element that is fully selected.
<a name="line633"></a> */
<a name="line634"></a>function testFontSizeDoesntOverrideStyleAttrMultiNode() {
<a name="line635"></a>  setUpFontSizeTests();
<a name="line636"></a>  FIELDMOCK.$replay();
<a name="line637"></a>
<a name="line638"></a>  HELPER.select(&#39;23&#39;, 1, &#39;56&#39;, 2); // Selects 3456.
<a name="line639"></a>  FORMATTER.execCommandInternal(
<a name="line640"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.FONT_SIZE, 6);
<a name="line641"></a>
<a name="line642"></a>  assertFontSizes(
<a name="line643"></a>      &#39;New font size shouldn\&#39;t override existing font size before &#39; +
<a name="line644"></a>      &#39;selection, but still override existing font size in last span&#39;,
<a name="line645"></a>      {&#39;2&#39;: 2, &#39;23&#39;: null, &#39;3&#39;: 32, &#39;4&#39;: 32, &#39;56&#39;: 32});
<a name="line646"></a>
<a name="line647"></a>  FIELDMOCK.$verify();
<a name="line648"></a>}
<a name="line649"></a>
<a name="line650"></a>
<a name="line651"></a>/**
<a name="line652"></a> * Helper to make sure the precondition that executing the font size command
<a name="line653"></a> * wraps the content in font tags instead of modifying the style attribute is
<a name="line654"></a> * maintained by the browser even if the selection is already text that is
<a name="line655"></a> * wrapped in a tag with a font size style. We test this with several
<a name="line656"></a> * permutations of how the selection looks: selecting the text in the text
<a name="line657"></a> * node, selecting the whole text node as a unit, or selecting the whole span
<a name="line658"></a> * node as a unit. Sometimes the browser wraps the text node with the font
<a name="line659"></a> * tag, sometimes it wraps the span with the font tag. Either one is ok as
<a name="line660"></a> * long as a font tag is actually being used instead of just modifying the
<a name="line661"></a> * span&#39;s style, because our fix for {@bug 1286408} would remove that style.
<a name="line662"></a> * @param {function} doSelect Function to select the &quot;23&quot; text in the test
<a name="line663"></a> *     content.
<a name="line664"></a> */
<a name="line665"></a>function doTestFontSizeStyledSpan(doSelect) {
<a name="line666"></a>  // Make sure no new browsers start getting this bad behavior. If they do,
<a name="line667"></a>  // this test will unexpectedly pass.
<a name="line668"></a>  expectedFailures.expectFailureFor(
<a name="line669"></a>      !goog.editor.BrowserFeature.DOESNT_OVERRIDE_FONT_SIZE_IN_STYLE_ATTR);
<a name="line670"></a>
<a name="line671"></a>  try {
<a name="line672"></a>    setUpFontSizeTests();
<a name="line673"></a>    FIELDMOCK.$replay();
<a name="line674"></a>
<a name="line675"></a>    doSelect();
<a name="line676"></a>    FORMATTER.execCommandInternal(
<a name="line677"></a>        goog.editor.plugins.BasicTextFormatter.COMMAND.FONT_SIZE, 7);
<a name="line678"></a>    var parentNode = HELPER.findTextNode(&#39;23&#39;).parentNode;
<a name="line679"></a>    var grandparentNode = parentNode.parentNode;
<a name="line680"></a>    var fontNode = goog.dom.getElementsByTagNameAndClass(goog.dom.TagName.FONT,
<a name="line681"></a>        undefined, ROOT)[0];
<a name="line682"></a>    var spanNode = goog.dom.getElementsByTagNameAndClass(goog.dom.TagName.SPAN,
<a name="line683"></a>        undefined, ROOT)[0];
<a name="line684"></a>    assertTrue(&#39;A font tag should have been added either outside or inside&#39; +
<a name="line685"></a>        &#39; the existing span&#39;,
<a name="line686"></a>        parentNode == spanNode &amp;&amp; grandparentNode == fontNode ||
<a name="line687"></a>        parentNode == fontNode &amp;&amp; grandparentNode == spanNode);
<a name="line688"></a>
<a name="line689"></a>    FIELDMOCK.$verify();
<a name="line690"></a>  } catch (e) {
<a name="line691"></a>    expectedFailures.handleException(e);
<a name="line692"></a>  }
<a name="line693"></a>}
<a name="line694"></a>
<a name="line695"></a>function testFontSizeStyledSpanSelectingText() {
<a name="line696"></a>  doTestFontSizeStyledSpan(function() {
<a name="line697"></a>    HELPER.select(&#39;23&#39;, 0, &#39;23&#39;, 2);
<a name="line698"></a>  });
<a name="line699"></a>}
<a name="line700"></a>
<a name="line701"></a>function testFontSizeStyledSpanSelectingTextNode() {
<a name="line702"></a>  doTestFontSizeStyledSpan(function() {
<a name="line703"></a>    var textNode = HELPER.findTextNode(&#39;23&#39;);
<a name="line704"></a>    HELPER.select(textNode.parentNode, 0, textNode.parentNode, 1);
<a name="line705"></a>  });
<a name="line706"></a>}
<a name="line707"></a>
<a name="line708"></a>function testFontSizeStyledSpanSelectingSpanNode() {
<a name="line709"></a>  doTestFontSizeStyledSpan(function() {
<a name="line710"></a>    var spanNode = HELPER.findTextNode(&#39;23&#39;).parentNode;
<a name="line711"></a>    HELPER.select(spanNode.parentNode, 1, spanNode.parentNode, 2);
<a name="line712"></a>  });
<a name="line713"></a>}
<a name="line714"></a>
<a name="line715"></a>function setUpIframeField(content) {
<a name="line716"></a>  var ifr = document.getElementById(&#39;iframe&#39;);
<a name="line717"></a>  var body = ifr.contentWindow.document.body;
<a name="line718"></a>  body.innerHTML = content;
<a name="line719"></a>
<a name="line720"></a>  HELPER = new goog.testing.editor.TestHelper(body);
<a name="line721"></a>  HELPER.setUpEditableElement();
<a name="line722"></a>  FIELDMOCK = new goog.testing.editor.FieldMock(ifr.contentWindow);
<a name="line723"></a>  FIELDMOCK.getElement();
<a name="line724"></a>  FIELDMOCK.$anyTimes();
<a name="line725"></a>  FIELDMOCK.$returns(body);
<a name="line726"></a>  FIELDMOCK.queryCommandValue(&#39;rtl&#39;);
<a name="line727"></a>  FIELDMOCK.$anyTimes();
<a name="line728"></a>  FIELDMOCK.$returns(null);
<a name="line729"></a>  FORMATTER.fieldObject = FIELDMOCK;
<a name="line730"></a>}
<a name="line731"></a>
<a name="line732"></a>function tearDownIframeField() {
<a name="line733"></a>  tearDownHelper();
<a name="line734"></a>}
<a name="line735"></a>
<a name="line736"></a>function setUpConvertBreaksToDivTests() {
<a name="line737"></a>  ROOT.innerHTML = &#39;&lt;p&gt;paragraph&lt;/p&gt;one&lt;br id=&quot;br1&quot;&gt;two&lt;br&gt;&lt;br&gt;&lt;br&gt;three&#39;;
<a name="line738"></a>  HELPER = new goog.testing.editor.TestHelper(ROOT);
<a name="line739"></a>  HELPER.setUpEditableElement();
<a name="line740"></a>
<a name="line741"></a>  FIELDMOCK.getElement();
<a name="line742"></a>  FIELDMOCK.$anyTimes();
<a name="line743"></a>  FIELDMOCK.$returns(ROOT);
<a name="line744"></a>}
<a name="line745"></a>
<a name="line746"></a>function tearDownConvertBreaksToDivTests() {
<a name="line747"></a>  tearDownHelper();
<a name="line748"></a>}
<a name="line749"></a>
<a name="line750"></a>
<a name="line751"></a>/** @bug 1414941 */
<a name="line752"></a>function testConvertBreaksToDivsKeepsP() {
<a name="line753"></a>  if (goog.editor.BrowserFeature.CAN_LISTIFY_BR) {
<a name="line754"></a>    return;
<a name="line755"></a>  }
<a name="line756"></a>  setUpConvertBreaksToDivTests();
<a name="line757"></a>  FIELDMOCK.$replay();
<a name="line758"></a>
<a name="line759"></a>  HELPER.select(&#39;three&#39;, 0);
<a name="line760"></a>  FORMATTER.convertBreaksToDivs_();
<a name="line761"></a>  assertEquals(&#39;There should still be a &lt;p&gt; tag&#39;,
<a name="line762"></a>               1, FIELDMOCK.getElement().getElementsByTagName(&#39;p&#39;).length);
<a name="line763"></a>  var html = FIELDMOCK.getElement().innerHTML.toLowerCase();
<a name="line764"></a>  assertNotBadBrElements(html);
<a name="line765"></a>  assertNotContains(&#39;There should not be empty &lt;div&gt; elements&#39;,
<a name="line766"></a>                    &#39;&lt;div&gt;&lt;\/div&gt;&#39;, html);
<a name="line767"></a>
<a name="line768"></a>  FIELDMOCK.$verify();
<a name="line769"></a>  tearDownConvertBreaksToDivTests();
<a name="line770"></a>}
<a name="line771"></a>
<a name="line772"></a>
<a name="line773"></a>/**
<a name="line774"></a>* @bug 1414937
<a name="line775"></a>* @bug 934535
<a name="line776"></a>*/
<a name="line777"></a>function testConvertBreaksToDivsDoesntCollapseBR() {
<a name="line778"></a>  if (goog.editor.BrowserFeature.CAN_LISTIFY_BR) {
<a name="line779"></a>    return;
<a name="line780"></a>  }
<a name="line781"></a>  setUpConvertBreaksToDivTests();
<a name="line782"></a>  FIELDMOCK.$replay();
<a name="line783"></a>
<a name="line784"></a>  HELPER.select(&#39;three&#39;, 0);
<a name="line785"></a>  FORMATTER.convertBreaksToDivs_();
<a name="line786"></a>  var html = FIELDMOCK.getElement().innerHTML.toLowerCase();
<a name="line787"></a>  assertNotBadBrElements(html);
<a name="line788"></a>  assertNotContains(&#39;There should not be empty &lt;div&gt; elements&#39;,
<a name="line789"></a>                    &#39;&lt;div&gt;&lt;\/div&gt;&#39;, html);
<a name="line790"></a>  if (goog.userAgent.IE) {
<a name="line791"></a>    // &lt;div&gt;&lt;br&gt;&lt;/div&gt; misbehaves in IE
<a name="line792"></a>    assertNotContains(
<a name="line793"></a>        &#39;&lt;br&gt; should not be used to prevent &lt;div&gt; from collapsing&#39;,
<a name="line794"></a>        &#39;&lt;div&gt;&lt;br&gt;&lt;\/div&gt;&#39;, html);
<a name="line795"></a>  }
<a name="line796"></a>
<a name="line797"></a>  FIELDMOCK.$verify();
<a name="line798"></a>  tearDownConvertBreaksToDivTests();
<a name="line799"></a>}
<a name="line800"></a>
<a name="line801"></a>function testConvertBreaksToDivsSelection() {
<a name="line802"></a>  if (goog.editor.BrowserFeature.CAN_LISTIFY_BR) {
<a name="line803"></a>    return;
<a name="line804"></a>  }
<a name="line805"></a>  setUpConvertBreaksToDivTests();
<a name="line806"></a>  FIELDMOCK.$replay();
<a name="line807"></a>
<a name="line808"></a>  HELPER.select(&#39;two&#39;, 1, &#39;three&#39;, 3);
<a name="line809"></a>  var before = FIELDMOCK.getRange().getText().replace(/\s/g, &#39;&#39;);
<a name="line810"></a>  FORMATTER.convertBreaksToDivs_();
<a name="line811"></a>  assertEquals(&#39;Selection must not be changed&#39;,
<a name="line812"></a>               before, FIELDMOCK.getRange().getText().replace(/\s/g, &#39;&#39;));
<a name="line813"></a>
<a name="line814"></a>  FIELDMOCK.$verify();
<a name="line815"></a>  tearDownConvertBreaksToDivTests();
<a name="line816"></a>}
<a name="line817"></a>
<a name="line818"></a>
<a name="line819"></a>/** @bug 1414937 */
<a name="line820"></a>function testConvertBreaksToDivsInsertList() {
<a name="line821"></a>  setUpConvertBreaksToDivTests();
<a name="line822"></a>  FIELDMOCK.$replay();
<a name="line823"></a>
<a name="line824"></a>  HELPER.select(&#39;three&#39;, 0);
<a name="line825"></a>  FORMATTER.execCommandInternal(&#39;insertorderedlist&#39;);
<a name="line826"></a>  assertTrue(&#39;Ordered list must be inserted&#39;,
<a name="line827"></a>             FIELDMOCK.getEditableDomHelper().getDocument().queryCommandState(
<a name="line828"></a>                 &#39;insertorderedlist&#39;));
<a name="line829"></a>  tearDownConvertBreaksToDivTests();
<a name="line830"></a>}
<a name="line831"></a>
<a name="line832"></a>
<a name="line833"></a>/**
<a name="line834"></a> * Regression test for {@bug 1939883}, where if a br has an id, it causes
<a name="line835"></a> * the convert br code to throw a js error. This goes a step further and
<a name="line836"></a> * ensures that the id is preserved in the resulting div element.
<a name="line837"></a> */
<a name="line838"></a>function testConvertBreaksToDivsKeepsId() {
<a name="line839"></a>  if (goog.editor.BrowserFeature.CAN_LISTIFY_BR) {
<a name="line840"></a>    return;
<a name="line841"></a>  }
<a name="line842"></a>  setUpConvertBreaksToDivTests();
<a name="line843"></a>  FIELDMOCK.$replay();
<a name="line844"></a>
<a name="line845"></a>  HELPER.select(&#39;one&#39;, 0, &#39;two&#39;, 0);
<a name="line846"></a>  FORMATTER.convertBreaksToDivs_();
<a name="line847"></a>  var html = FIELDMOCK.getElement().innerHTML.toLowerCase();
<a name="line848"></a>  assertNotBadBrElements(html);
<a name="line849"></a>  var idBr = document.getElementById(&#39;br1&#39;);
<a name="line850"></a>  assertNotNull(&#39;There should still be a tag with id=&quot;br1&quot;&#39;, idBr);
<a name="line851"></a>  assertEquals(&#39;The tag with id=&quot;br1&quot; should be a &lt;div&gt; now&#39;,
<a name="line852"></a>               goog.dom.TagName.DIV,
<a name="line853"></a>               idBr.tagName);
<a name="line854"></a>  assertNull(&#39;There should not be any tag with id=&quot;temp_br&quot;&#39;,
<a name="line855"></a>             document.getElementById(&#39;temp_br&#39;));
<a name="line856"></a>
<a name="line857"></a>  FIELDMOCK.$verify();
<a name="line858"></a>  tearDownConvertBreaksToDivTests();
<a name="line859"></a>}
<a name="line860"></a>
<a name="line861"></a>
<a name="line862"></a>/**
<a name="line863"></a> * @bug 2420054
<a name="line864"></a> */
<a name="line865"></a>var JUSTIFICATION_COMMANDS = [
<a name="line866"></a>  goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT,
<a name="line867"></a>  goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT,
<a name="line868"></a>  goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_CENTER,
<a name="line869"></a>  goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_FULL
<a name="line870"></a>];
<a name="line871"></a>function doTestIsJustification(command) {
<a name="line872"></a>  setUpRealField();
<a name="line873"></a>  REAL_FIELD.setHtml(false, &#39;foo&#39;);
<a name="line874"></a>  selectRealField();
<a name="line875"></a>  REAL_FIELD.execCommand(command);
<a name="line876"></a>
<a name="line877"></a>  for (var i = 0; i &lt; JUSTIFICATION_COMMANDS.length; i++) {
<a name="line878"></a>    if (JUSTIFICATION_COMMANDS[i] == command) {
<a name="line879"></a>      assertTrue(&#39;queryCommandValue(&#39; + JUSTIFICATION_COMMANDS[i] +
<a name="line880"></a>                 &#39;) should be true after execCommand(&#39; + command + &#39;)&#39;,
<a name="line881"></a>          REAL_FIELD.queryCommandValue(JUSTIFICATION_COMMANDS[i]));
<a name="line882"></a>    } else {
<a name="line883"></a>      assertFalse(&#39;queryCommandValue(&#39; + JUSTIFICATION_COMMANDS[i] +
<a name="line884"></a>          &#39;) should be false after execCommand(&#39; + command + &#39;)&#39;,
<a name="line885"></a>          REAL_FIELD.queryCommandValue(JUSTIFICATION_COMMANDS[i]));
<a name="line886"></a>    }
<a name="line887"></a>  }
<a name="line888"></a>}
<a name="line889"></a>function testIsJustificationLeft() {
<a name="line890"></a>  doTestIsJustification(
<a name="line891"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT);
<a name="line892"></a>}
<a name="line893"></a>function testIsJustificationRight() {
<a name="line894"></a>  doTestIsJustification(
<a name="line895"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT);
<a name="line896"></a>}
<a name="line897"></a>function testIsJustificationCenter() {
<a name="line898"></a>  doTestIsJustification(
<a name="line899"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_CENTER);
<a name="line900"></a>}
<a name="line901"></a>function testIsJustificationFull() {
<a name="line902"></a>  doTestIsJustification(
<a name="line903"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_FULL);
<a name="line904"></a>}
<a name="line905"></a>
<a name="line906"></a>
<a name="line907"></a>/**
<a name="line908"></a> * Regression test for {@bug 1414813}, where all 3 justification buttons are
<a name="line909"></a> * considered &quot;on&quot; when you first tab into the editable field. In this
<a name="line910"></a> * situation, when lorem ipsum is the only node in the editable field iframe
<a name="line911"></a> * body, mockField.getRange() returns an empty range.
<a name="line912"></a> */
<a name="line913"></a>function testIsJustificationEmptySelection() {
<a name="line914"></a>  var mockField = new goog.testing.LooseMock(goog.editor.Field);
<a name="line915"></a>
<a name="line916"></a>  mockField.getRange();
<a name="line917"></a>  mockField.$anyTimes();
<a name="line918"></a>  mockField.$returns(null);
<a name="line919"></a>  mockField.getPluginByClassId(&#39;Bidi&#39;);
<a name="line920"></a>  mockField.$anyTimes();
<a name="line921"></a>  mockField.$returns(null);
<a name="line922"></a>  FORMATTER.fieldObject = mockField;
<a name="line923"></a>
<a name="line924"></a>  mockField.$replay();
<a name="line925"></a>
<a name="line926"></a>  assertFalse(&#39;Empty selection should not be justified&#39;,
<a name="line927"></a>              FORMATTER.isJustification_(
<a name="line928"></a>                  goog.editor.plugins.BasicTextFormatter.
<a name="line929"></a>                  COMMAND.JUSTIFY_CENTER));
<a name="line930"></a>  assertFalse(&#39;Empty selection should not be justified&#39;,
<a name="line931"></a>              FORMATTER.isJustification_(
<a name="line932"></a>                  goog.editor.plugins.BasicTextFormatter.
<a name="line933"></a>                  COMMAND.JUSTIFY_FULL));
<a name="line934"></a>  assertFalse(&#39;Empty selection should not be justified&#39;,
<a name="line935"></a>              FORMATTER.isJustification_(
<a name="line936"></a>                  goog.editor.plugins.BasicTextFormatter.
<a name="line937"></a>                  COMMAND.JUSTIFY_RIGHT));
<a name="line938"></a>  assertFalse(&#39;Empty selection should not be justified&#39;,
<a name="line939"></a>              FORMATTER.isJustification_(
<a name="line940"></a>                  goog.editor.plugins.BasicTextFormatter.
<a name="line941"></a>                  COMMAND.JUSTIFY_LEFT));
<a name="line942"></a>
<a name="line943"></a>  mockField.$verify();
<a name="line944"></a>}
<a name="line945"></a>
<a name="line946"></a>function testIsJustificationSimple1() {
<a name="line947"></a>  setUpRealField();
<a name="line948"></a>  REAL_FIELD.setHtml(false, &#39;&lt;div align=&quot;right&quot;&gt;foo&lt;/div&gt;&#39;);
<a name="line949"></a>  selectRealField();
<a name="line950"></a>
<a name="line951"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line952"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT));
<a name="line953"></a>  assertTrue(REAL_FIELD.queryCommandValue(
<a name="line954"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT));
<a name="line955"></a>}
<a name="line956"></a>
<a name="line957"></a>function testIsJustificationSimple2() {
<a name="line958"></a>  setUpRealField();
<a name="line959"></a>  REAL_FIELD.setHtml(false, &#39;&lt;div style=&quot;text-align: right;&quot;&gt;foo&lt;/div&gt;&#39;);
<a name="line960"></a>  selectRealField();
<a name="line961"></a>
<a name="line962"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line963"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT));
<a name="line964"></a>  assertTrue(REAL_FIELD.queryCommandValue(
<a name="line965"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT));
<a name="line966"></a>}
<a name="line967"></a>
<a name="line968"></a>function testIsJustificationComplete1() {
<a name="line969"></a>  setUpRealField();
<a name="line970"></a>  REAL_FIELD.setHtml(false,
<a name="line971"></a>      &#39;&lt;div align=&quot;left&quot;&gt;a&lt;/div&gt;&lt;div align=&quot;right&quot;&gt;b&lt;/div&gt;&#39;);
<a name="line972"></a>  selectRealField();
<a name="line973"></a>
<a name="line974"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line975"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT));
<a name="line976"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line977"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT));
<a name="line978"></a>}
<a name="line979"></a>
<a name="line980"></a>function testIsJustificationComplete2() {
<a name="line981"></a>  setUpRealField();
<a name="line982"></a>  REAL_FIELD.setHtml(false,
<a name="line983"></a>      &#39;&lt;div align=&quot;left&quot;&gt;a&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;b&lt;/div&gt;&#39;);
<a name="line984"></a>  selectRealField();
<a name="line985"></a>
<a name="line986"></a>  assertTrue(REAL_FIELD.queryCommandValue(
<a name="line987"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT));
<a name="line988"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line989"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT));
<a name="line990"></a>}
<a name="line991"></a>
<a name="line992"></a>function testIsJustificationComplete3() {
<a name="line993"></a>  setUpRealField();
<a name="line994"></a>  REAL_FIELD.setHtml(false,
<a name="line995"></a>      &#39;&lt;div align=&quot;right&quot;&gt;a&lt;/div&gt;&lt;div align=&quot;right&quot;&gt;b&lt;/div&gt;&#39;);
<a name="line996"></a>  selectRealField();
<a name="line997"></a>
<a name="line998"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line999"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT));
<a name="line1000"></a>  assertTrue(REAL_FIELD.queryCommandValue(
<a name="line1001"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT));
<a name="line1002"></a>}
<a name="line1003"></a>
<a name="line1004"></a>function testIsJustificationComplete4() {
<a name="line1005"></a>  setUpRealField();
<a name="line1006"></a>  REAL_FIELD.setHtml(false,
<a name="line1007"></a>      &#39;&lt;div align=&quot;right&quot;&gt;&lt;div align=&quot;left&quot;&gt;a&lt;/div&gt;&lt;/div&gt;&#39; +
<a name="line1008"></a>      &#39;&lt;div align=&quot;right&quot;&gt;b&lt;/div&gt;&#39;);
<a name="line1009"></a>  selectRealField();
<a name="line1010"></a>
<a name="line1011"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line1012"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT));
<a name="line1013"></a>  assertTrue(REAL_FIELD.queryCommandValue(
<a name="line1014"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT));
<a name="line1015"></a>}
<a name="line1016"></a>
<a name="line1017"></a>function testIsJustificationComplete5() {
<a name="line1018"></a>  setUpRealField();
<a name="line1019"></a>  REAL_FIELD.setHtml(false,
<a name="line1020"></a>      &#39;&lt;div align=&quot;right&quot;&gt;a&lt;/div&gt;b&#39; +
<a name="line1021"></a>      &#39;&lt;div align=&quot;right&quot;&gt;c&lt;/div&gt;&#39;);
<a name="line1022"></a>  selectRealField();
<a name="line1023"></a>
<a name="line1024"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line1025"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT));
<a name="line1026"></a>  assertFalse(REAL_FIELD.queryCommandValue(
<a name="line1027"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT));
<a name="line1028"></a>}
<a name="line1029"></a>
<a name="line1030"></a>
<a name="line1031"></a>/** @bug 2472589 */
<a name="line1032"></a>function doTestIsJustificationPInDiv(useCss, align, command) {
<a name="line1033"></a>  setUpRealField();
<a name="line1034"></a>  var html = &#39;&lt;div &#39; + (useCss ? &#39;style=&quot;text-align:&#39; : &#39;align=&quot;&#39;) +
<a name="line1035"></a>      align + &#39;&quot;&gt;&lt;p&gt;foo&lt;/p&gt;&lt;/div&gt;&#39;;
<a name="line1036"></a>
<a name="line1037"></a>  REAL_FIELD.setHtml(false, html);
<a name="line1038"></a>  selectRealField();
<a name="line1039"></a>  assertTrue(
<a name="line1040"></a>      &#39;P inside &#39; + align + &#39; aligned&#39; + (useCss ? &#39; (using CSS)&#39; : &#39;&#39;) +
<a name="line1041"></a>          &#39; DIV should be considered &#39; + align + &#39; aligned&#39;,
<a name="line1042"></a>      REAL_FIELD.queryCommandValue(command));
<a name="line1043"></a>}
<a name="line1044"></a>function testIsJustificationPInDivLeft() {
<a name="line1045"></a>  doTestIsJustificationPInDiv(false, &#39;left&#39;,
<a name="line1046"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT);
<a name="line1047"></a>}
<a name="line1048"></a>function testIsJustificationPInDivRight() {
<a name="line1049"></a>  doTestIsJustificationPInDiv(false, &#39;right&#39;,
<a name="line1050"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT);
<a name="line1051"></a>}
<a name="line1052"></a>function testIsJustificationPInDivCenter() {
<a name="line1053"></a>  doTestIsJustificationPInDiv(false, &#39;center&#39;,
<a name="line1054"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_CENTER);
<a name="line1055"></a>}
<a name="line1056"></a>function testIsJustificationPInDivJustify() {
<a name="line1057"></a>  doTestIsJustificationPInDiv(false, &#39;justify&#39;,
<a name="line1058"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_FULL);
<a name="line1059"></a>}
<a name="line1060"></a>function testIsJustificationPInDivLeftCss() {
<a name="line1061"></a>  doTestIsJustificationPInDiv(true, &#39;left&#39;,
<a name="line1062"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_LEFT);
<a name="line1063"></a>}
<a name="line1064"></a>function testIsJustificationPInDivRightCss() {
<a name="line1065"></a>  doTestIsJustificationPInDiv(true, &#39;right&#39;,
<a name="line1066"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_RIGHT);
<a name="line1067"></a>}
<a name="line1068"></a>function testIsJustificationPInDivCenterCss() {
<a name="line1069"></a>  doTestIsJustificationPInDiv(true, &#39;center&#39;,
<a name="line1070"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_CENTER);
<a name="line1071"></a>}
<a name="line1072"></a>function testIsJustificationPInDivJustifyCss() {
<a name="line1073"></a>  doTestIsJustificationPInDiv(true, &#39;justify&#39;,
<a name="line1074"></a>      goog.editor.plugins.BasicTextFormatter.COMMAND.JUSTIFY_FULL);
<a name="line1075"></a>}
<a name="line1076"></a>
<a name="line1077"></a>
<a name="line1078"></a>function testPrepareContent() {
<a name="line1079"></a>  setUpRealField();
<a name="line1080"></a>  assertPreparedContents(&#39;\n&#39;, &#39;\n&#39;);
<a name="line1081"></a>
<a name="line1082"></a>  if (goog.editor.BrowserFeature.COLLAPSES_EMPTY_NODES) {
<a name="line1083"></a>    assertPreparedContents(&quot;&amp;nbsp;&lt;script&gt;alert(&#39;hi&#39;)&lt;&quot; + &#39;/script&gt;&#39;,
<a name="line1084"></a>        &quot;&lt;script&gt;alert(&#39;hi&#39;)&lt;&quot; + &#39;/script&gt;&#39;);
<a name="line1085"></a>  } else {
<a name="line1086"></a>    assertNotPreparedContents(&quot;&lt;script&gt;alert(&#39;hi&#39;)&lt;&quot; + &#39;/script&gt;&#39;);
<a name="line1087"></a>  }
<a name="line1088"></a>
<a name="line1089"></a>  if (goog.editor.BrowserFeature.CONVERT_TO_B_AND_I_TAGS) {
<a name="line1090"></a>    assertPreparedContents(&#39;&lt;b id=\&#39;foo\&#39;&gt;hi&lt;/b&gt;&#39;,
<a name="line1091"></a>        &#39;&lt;strong id=\&#39;foo\&#39;&gt;hi&lt;/strong&gt;&#39;);
<a name="line1092"></a>    assertPreparedContents(&#39;&lt;i&gt;hi&lt;/i&gt;&#39;, &#39;&lt;em&gt;hi&lt;/em&gt;&#39;);
<a name="line1093"></a>    assertNotPreparedContents(&#39;&lt;embed&gt;&#39;);
<a name="line1094"></a>  } else {
<a name="line1095"></a>    assertNotPreparedContents(&#39;&lt;em&gt;hi&lt;/em&gt;&#39;);
<a name="line1096"></a>    assertNotPreparedContents(&#39;&lt;strong id=\&#39;foo\&#39;&gt;hi&lt;/strong&gt;&#39;);
<a name="line1097"></a>  }
<a name="line1098"></a>}
<a name="line1099"></a>
<a name="line1100"></a>function testScrubImagesRemovesCustomAttributes() {
<a name="line1101"></a>  var fieldElem = goog.dom.getElement(&#39;real-field&#39;);
<a name="line1102"></a>  fieldElem.innerHTML = &#39;&#39;;
<a name="line1103"></a>  var attrs = {&#39;src&#39;: &#39;http://www.google.com/foo.jpg&#39;,
<a name="line1104"></a>    &#39;tabIndex&#39;: &#39;0&#39;,
<a name="line1105"></a>    &#39;tabIndexSet&#39;: &#39;0&#39;};
<a name="line1106"></a>  attrs[goog.HASH_CODE_PROPERTY_] = &#39;0&#39;;
<a name="line1107"></a>  goog.dom.appendChild(fieldElem,
<a name="line1108"></a>      goog.dom.createDom(&#39;img&#39;, attrs));
<a name="line1109"></a>
<a name="line1110"></a>  setUpRealField();
<a name="line1111"></a>
<a name="line1112"></a>  var html = REAL_FIELD.getCleanContents();
<a name="line1113"></a>  assert(&#39;Images must not have forbidden attributes: &#39; + html,
<a name="line1114"></a>      -1 == html.indexOf(&#39;tabIndex&#39;) &amp;&amp; -1 == html.indexOf(&#39;closure&#39;));
<a name="line1115"></a>  assert(&#39;Image URLs must not be made relative by default: &#39; + html,
<a name="line1116"></a>      -1 != html.indexOf(&#39;/foo.jpg&#39;));
<a name="line1117"></a>}
<a name="line1118"></a>
<a name="line1119"></a>function testGeckoSelectionChange() {
<a name="line1120"></a>  if (!goog.userAgent.GECKO || !goog.userAgent.isVersionOrHigher(&#39;1.9&#39;)) {
<a name="line1121"></a>    return;
<a name="line1122"></a>  }
<a name="line1123"></a>
<a name="line1124"></a>  setUpRealFieldIframe();
<a name="line1125"></a>  // Use native selection for this test because goog.dom.Range will
<a name="line1126"></a>  // change selections of &lt;br&gt;
<a name="line1127"></a>  var ifr = document.getElementById(&#39;iframe&#39;);
<a name="line1128"></a>  ifr.contentWindow.document.body.innerHTML = &#39;hello&lt;br id=&quot;br1&quot;&gt;&lt;br id=&quot;br2&quot;&gt;&#39;;
<a name="line1129"></a>  var body = ifr.contentWindow.document.body;
<a name="line1130"></a>  var range = REAL_FIELD.getRange();
<a name="line1131"></a>  var browserRange = range.getBrowserRangeObject();
<a name="line1132"></a>  browserRange.setStart(body, 2);
<a name="line1133"></a>  browserRange.setEnd(body, 2);
<a name="line1134"></a>  FORMATTER.applyExecCommandGeckoFixes_(&#39;formatblock&#39;);
<a name="line1135"></a>  var updatedRange = REAL_FIELD.getRange().getBrowserRangeObject();
<a name="line1136"></a>  assertEquals(&#39;Range should have been updated to deep range&#39;,
<a name="line1137"></a>      &#39;br2&#39;, updatedRange.startContainer.id);
<a name="line1138"></a>  assertEquals(&#39;Range should have been updated to deep range&#39;,
<a name="line1139"></a>      0, updatedRange.startOffset);
<a name="line1140"></a>}
<a name="line1141"></a>
<a name="line1142"></a>function testIEExecCommandFixes() {
<a name="line1143"></a>  if (!goog.userAgent.IE) {
<a name="line1144"></a>    return;
<a name="line1145"></a>  }
<a name="line1146"></a>
<a name="line1147"></a>  setUpRealField();
<a name="line1148"></a>  REAL_FIELD.setHtml(false, &#39;&lt;blockquote&gt;hi&lt;/blockquote&gt;&#39;);
<a name="line1149"></a>  goog.dom.Range.createFromNodeContents(REAL_FIELD.getElement()).select();
<a name="line1150"></a>
<a name="line1151"></a>  var nodes = REAL_PLUGIN.applyExecCommandIEFixes_(&#39;insertOrderedList&#39;);
<a name="line1152"></a>  assertHTMLEquals(
<a name="line1153"></a>      &#39;&lt;blockquote&gt;hi &lt;div style=&quot;height:0px&quot;&gt;&lt;/div&gt;&lt;/blockquote&gt;&#39;,
<a name="line1154"></a>      REAL_FIELD.getCleanContents());
<a name="line1155"></a>}
<a name="line1156"></a>
<a name="line1157"></a>
<a name="line1158"></a>/**
<a name="line1159"></a> * Assert that the prepared contents matches the expected.
<a name="line1160"></a> */
<a name="line1161"></a>function assertPreparedContents(expected, original) {
<a name="line1162"></a>  assertEquals(expected,
<a name="line1163"></a>      REAL_FIELD.reduceOp_(
<a name="line1164"></a>          goog.editor.Plugin.Op.PREPARE_CONTENTS_HTML, original));
<a name="line1165"></a>}
<a name="line1166"></a>
<a name="line1167"></a>
<a name="line1168"></a>/**
<a name="line1169"></a> * Assert that sanitization doesn&#39;t affect the given text.
<a name="line1170"></a> */
<a name="line1171"></a>function assertNotPreparedContents(text) {
<a name="line1172"></a>  assertPreparedContents(text, text);
<a name="line1173"></a>}
<a name="line1174"></a>
<a name="line1175"></a>
<a name="line1176"></a>/**
<a name="line1177"></a> * Assert that only BR elements expected to persist after convertBreaksToDivs_
<a name="line1178"></a> * are in the HTML.
<a name="line1179"></a> */
<a name="line1180"></a>function assertNotBadBrElements(html) {
<a name="line1181"></a>  if (goog.userAgent.IE) {
<a name="line1182"></a>    assertNotContains(&#39;There should not be &lt;br&gt; elements&#39;, &#39;&lt;br&#39;, html);
<a name="line1183"></a>  } else {
<a name="line1184"></a>    assertFalse(&#39;There should not be &lt;br&gt; elements, except ones to prevent &#39; +
<a name="line1185"></a>        &#39;&lt;div&gt;s from collapsing&#39; + html,
<a name="line1186"></a>        /(?!&lt;div&gt;)&lt;br&gt;(?!&lt;\/div&gt;)/.test(html));
<a name="line1187"></a>  }
<a name="line1188"></a>}
</pre>


</body>
</html>
